package com.zero.mxshengadmin.modules.website.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zero.mxshengadmin.common.exception.RRException;
import com.zero.mxshengadmin.common.utils.PageUtils;
import com.zero.mxshengadmin.common.utils.Query;
import com.zero.mxshengadmin.modules.website.dao.WebsiteNewsDao;
import com.zero.mxshengadmin.modules.website.entity.WebsiteNewsEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteNewsService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by aicaikeji on 2019/4/3.
 */
@Service("websiteNewsService")
public class WebsiteNewsServiceImpl extends ServiceImpl<WebsiteNewsDao,WebsiteNewsEntity> implements WebsiteNewsService {


    /**
     * 添加资讯
     * @param entity
     * @return
     */
    @Override
    public void save(WebsiteNewsEntity entity) {
        boolean save = this.insert(entity);
        if (!save) throw new RRException("操作失败");
    }


    /**
     * 查询资讯详情
     * @param id
     * @return
     */
    @Override
    public WebsiteNewsEntity getById(long id) {
        WebsiteNewsEntity entity = this.selectById(id);
        if (entity == null) {
            throw  new RRException("操作失败");
        }else {
            return entity;
        }
    }


    /**
     * 更新账户信息
     * @param entity
     * @return
     */
    @Override
    public void update(WebsiteNewsEntity entity) {
        boolean update = this.updateById(entity);
        if (!update) throw new RRException("操作失败");
    }


    /**
     * 删除账户信息
     * @param ids
     * @return
     */
    @Override
    public void removeByIds(Long[] ids) {
        this.deleteBatchIds(Arrays.asList(ids));
    }


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<WebsiteNewsEntity> page = this.selectPage(
                new Query<WebsiteNewsEntity>(params).getPage(),
                new EntityWrapper<>()
        );

        return new PageUtils(page);
    }
}
